﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SCCMInterop;
using Microsoft.ConfigurationManagement;
using Microsoft.ConfigurationManagement.ManagementProvider;
using Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine;

namespace SccmObjectMove
{
    class MoveObject
    {
        WqlConnectionManager con;
        IResultObject SourceCol;
        IResultObject TargetCol;



        #region constructor

        public MoveObject(string Servername, string Username = null, string Password = null)
        {
            if (String.IsNullOrEmpty(Username) || String.IsNullOrEmpty(Password))
            {

                try
                {
                    this.con = CMInterop.connectSCCMServer(Servername, null, null);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
            else
            {
                try
                {
                    this.con = CMInterop.connectSCCMServer(Servername, Username, Password);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

        public MoveObject(WqlConnectionManager Connection)
        {
            this.con = Connection;
        }

        #endregion

        public void StartMove(string SourceCollectionID, string TargetCollectionID)
        {
            // Check if the collections exists
            
            // SourceCollection
            try
            {
                SourceCol = CMInterop.getSCCMCollection(this.con, @"CollectionID='" + SourceCollectionID + "'");
                
            }
            catch (Exception ex)
            {
                
                throw ex;
            }


            try
            {
                TargetCol = CMInterop.getSCCMCollection(this.con, @"CollectionID='" + TargetCollectionID + "'");

            }
            catch (Exception ex)
            {

                throw ex;
            }

        }


        #region properties

        public IResultObject Source
        {
            get { return this.SourceCol; }
        }

        public IResultObject Target
        {
            get { return this.TargetCol; }
        }

        #endregion



    }
}
